<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Support\Facades\Storage;

class BackupSqlFileCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'backup:sql:file';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    public function handle()
    {
        $from = Storage::disk('local_backup');
        $to = Storage::disk('oss_backup');
        $data = $from->allFiles();
        foreach ($data as $path) {
            if (!$to->exists($path)) {
                try {
                    $to->put($path, $from->get($path));
                } catch (FileNotFoundException $e) {
                }
            }
            $from->delete($path);
        }
    }

}
